<?php
namespace app\admin\controller;

use think\Request;
use think\Controller;

/**
 * @author YangPan
 *
 */
class Base extends Controller
{
    protected $accessKey;       # 入口KEY值
    protected $adminSign;       # 账号校验KEY值
    protected $accountId;       # 客户ID
    protected $account;         # 客户账号
    protected $page;            # 分页参数
    protected $timeStamp;       # 当前时间戳

    public function _initialize()
    {
        $this->accessKey = config('custom.accessKey');
        $this->adminSign = config('custom.adminKey');
        $this->accountId = session('user_id');
        $this->page = 30;
        $this->timeStamp = time();
     
        $request=Request::instance();
        // // 控制器名
        $controller=$request->controller();
        // // 获取方法名
        $action=$request->action();
        $name=$controller.'/'.$action;

        
        // 不需要做入口验证的方法
        // $notCheck = ['login'];
        $notCheck=array('Index/welcome','Index/login','Index/logout','Index/index');

    }
    
    
    /**
     * 阿里云OSS上传---字符串上次方式
     * @access public
     * @param  string   $object 阿里云OSS的存储路径，例如： images/huoduan20180315.jpg
     * @param  string   $Path   服务器本地的文件路径，例如： /home/www/huoduan/tmp/huoduan20180315.jpg
     * @param  string   $bucket   阿里云OSS的bucket名称，例如：huoduan
     * @return bool
     */
    function ossUpload($object,$content,$bucket='')
    {
        Vendor('aliyun-oss-php-sdk-master.autoload');//引入文件
        
        //以下配置信息可以放到配置文件里
        $keyId = 'LTAIxAjNJExbFDAX';//您的Access Key ID
        $keySecret = 'uUVrCIrMrVuGH4pT9aQPFJQKBkqvv1';//Access Key Secret
        $endpoint = 'oss-cn-shanghai.aliyuncs.com';//阿里云oss外网地址endpoint

        $oss=new \OSS\OssClient($keyId,$keySecret,$endpoint);
        try{
            //$oss->uploadFile($bucket, $object, $content);
            $kk = $oss->putObject($bucket, $object, $content);
        } catch(\Exception $e) {
            return $e->getMessage();//如果出错返回错误
        }
        return $kk;
    }
    
    
    /**
     * 阿里云OSS -- 删除文件
     *
     * @param OssClient $ossClient OSSClient实例
     * @param string $bucket bucket名字
     * @return null
     */
    function deleteOssfile($object,$bucket='')
    {
        Vendor('aliyunoss.autoload');//引入文件
    
        //以下配置信息可以放到配置文件里
        $keyId = 'LTAIxAjNJExbFDAX';//您的Access Key ID
        $keySecret = 'uUVrCIrMrVuGH4pT9aQPFJQKBkqvv1';//Access Key Secret
        $endpoint = 'oss-cn-shanghai.aliyuncs.com';//阿里云oss外网地址endpoint
    
        $oss=new \OSS\OssClient($keyId,$keySecret,$endpoint);
        try{
            $oss_is = $oss->deleteObject($bucket, $object);
        } catch(\Exception $e) {
            return $e->getMessage();//如果出错返回错误
        }
        return $oss_is;
    }
    
    
    
}